﻿using System.Configuration;

namespace MeiWinForms.comm;

public static class Config
{
    private static readonly string BasePath = Path.Combine(Directory.GetCurrentDirectory(), "data");

    public static string DataPath(params string[] paths)
    {
        string p = BasePath;
        foreach (string path in paths)
        {
            // 如果路径不存在，则创建目录
            if (!Directory.Exists(p))
            {
                Directory.CreateDirectory(p);
            }

            // 拼接路径
            p = Path.Combine(p, path);
        }

        return p;
    }

    public static T GetConfig<T>() where T : ConfigurationSection
    {
        try
        {
            return (T)ConfigurationManager.GetSection(typeof(T).Name);
        }
        catch (Exception e)
        {
            Output.WriteOutput(e.Message);
            throw;
        }
    }
}